package com.yzc.controller;


import com.yzc.model.entity.system.Pve;
import com.yzc.model.entity.system.Tour;
import com.yzc.result.Result;
import com.yzc.service.PveService;
import com.yzc.service.TourService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tour")
public class TourController {

    private static final Marker LOG_MARKER = MarkerFactory.getMarker("LOG");
    @Autowired
    private TourService tourService;
    @Autowired
    private PveService pveService;


    @PostMapping("/selectBypvenameInfo")
    public Result<List<Pve>> selectBypvename(Pve pvename) {
        log.info(LOG_MARKER, "浏览了" + pvename + "景点");
        return Result.success(pveService.selectBypvename(pvename));
    }

    @PostMapping("/selectBypvenameOnaddress")
    public Result<List<Pve>> selectBypvenameOnaddress() {
        log.info(LOG_MARKER, "selectBypvenameOnaddress");
        return Result.success(pveService.selectBypvenameOnaddress());
    }

    @PostMapping("/loadAllTourData")
    public Result<List<Tour>> loadAll() {
        log.info(LOG_MARKER, "loadAllTourData");
        return Result.success(tourService.loadAllTourData());
    }


    @PostMapping("/selectBytournameInfo")
    public Result<List<Tour>> selectInfos(@RequestBody Tour tourname) {
        log.info(LOG_MARKER, "selectBytournameInfo");
        return Result.success(tourService.selectInfos(tourname));
    }


    @DeleteMapping("/deleteInfos")
    public Result deleteInfos(@RequestParam("tourid") int tourid) {
        tourService.deleteInfos(tourid);
        log.info(LOG_MARKER, "删除了一个景点");
        return Result.success();
    }

    @PostMapping("/saveInfos")
    public Result saveInfos(@RequestBody Tour tour) {
        tourService.saveOrUpdate(tour);
        log.info(LOG_MARKER, "saveInfos");
        return Result.success();
    }


    @PostMapping("/updateInfos")
    public Result updateInfos(@RequestBody Tour tour) {
        tourService.saveOrUpdate(tour);
        log.info(LOG_MARKER, "更新景点信息");
        return Result.success();
    }

    @GetMapping("/getTourid")
    public Result<Tour> getTourid(@RequestParam("tourid") Integer tourid) {
        log.info(LOG_MARKER, "getTourid");
        return Result.success(tourService.getTourid(tourid));
    }
}
